#include "Material.h"
POCELAIN_NAMESPACE_BEGIN
Material::Material()
{
}
Material::~Material()
{
}
// void Material::setFog(bool val)
// {
//     if(val != mFog)
//     {
//         mFog = val;
//         mDirty = true;
//     }
// }
void Material::setBlending(GLenum val)
{
    if(val != mBlending)
    {
        mBlending = val;
        mDirty = true;
    }
}

void Material::setSide(GLenum val)
{
    if(val != mSide)
    {
        mSide = val;
        mDirty = true;
    }
}

// void Material::setFlatShading(bool val)
// {
//     if(val != mFlatShading)
//     {
//         mFlatShading = val;
//         mDirty = true;
//     }
// }

void Material::setVertexColors(bool val)
{
    if(val != mVertexColors)
    {
        mVertexColors = val;
        mDirty = true;
    }
}

// void Material::setOpacity(Real val)
// {
//     if(val != mOpacity)
//     {
//         mOpacity = val;
//         mDirty = true;
//     }
// }

void Material::setTransparent(bool val)
{
    if(val != mTransparent)
    {
        mTransparent = val;
        mDirty = true;
    }
}

void Material::setBlendSrc(GLenum val)
{
    if(val != mBlendSrc)
    {
        mBlendSrc = val;
        mDirty = true;
    }
}

void Material::setBlendDst(GLenum val)
{
    if(val != mBlendDst)
    {
        mBlendDst = val;
        mDirty = true;
    }
}

void Material::setBlendEquation(GLenum val)
{
    if(val != mBlendEquation)
    {
        mBlendEquation = val;
        mDirty = true;
    }
}

void Material::setDepthFunc(GLenum val)
{
    if(val != mDepthFunc)
    {
        mDepthFunc = val;
        mDirty = true;
    }
}

void Material::setDepthTest(bool val) 
{
    if(val != mDepthTest)
    {
        mDepthTest = val;
        mDirty = true;
    }
}

void Material::setDepthWrite(bool val)
{
    if(val != mDepthWrite)
    {
        mDepthWrite = val;
        mDirty = true;
    }
}

void Material::setStencilWriteMask(uint32_t val)
{
    if(val != mStencilWriteMask)
    {
        mStencilWriteMask = val;
        mDirty = true;
    }
}

void Material::setStencilFunc(GLenum val)
{
    if(val != mStencilFunc)
    {
        mStencilFunc = val;
        mDirty = true;
    }
}
    
void Material::setStencilFuncMask(uint32_t val)
{
    if(val != mStencilFuncMask)
    {
        mStencilFuncMask = val;
        mDirty = true;
    }
}

void Material::setStencilFail(GLenum val)
{
    if(val != mStencilFail)
    {
        mStencilFail = val;
        mDirty = true;
    }
}

void Material::setStencilZFail(GLenum val)
{
    if(val != mStencilZFail)
    {
        mStencilZFail = val;
        mDirty = true;
    }
}

void Material::setStencilZPass(GLenum val)
{
    if(val != mStencilZPass)
    {
        mStencilZPass = val;
        mDirty = true;
    }
}

void Material::setStencilWrite(bool val)
{
    if(val != mStencilWrite)
    {
        mStencilWrite = val;
        mDirty = true;
    }
}

void Material::setClipIntersection(bool val)
{
    if(val != mClipIntersection)
    {
        mClipIntersection = val;
        mDirty = true;
    }
}

void Material::setClipShadows(bool val)
{
    if(val != mClipShadows)
    {
        mClipShadows = val;
        mDirty = true;
    }
}

void Material::setColorWrite(bool val)
{
    if(val != mColorWrite)
    {
        mColorWrite = val;
        mDirty = true;
    }
}
    
void Material::setPolygonOffset(bool val)
{
    if(val != mPolygonOffset)
    {
        mPolygonOffset = val;
        mDirty = true;
    }
}

void Material::setPolygonOffsetFactor (Real val)
{
    if(val != mPolygonOffsetFactor)
    {
        mPolygonOffsetFactor = val;
        mDirty = true;
    }
}

void Material::setPolygonOffsetUnits(Real val)
{
    if(val != mPolygonOffsetUnits)
    {
        mPolygonOffsetUnits = val;
        mDirty = true;
    }
}

void Material::setDithering(bool val)
{
    if(val != mDithering)
    {
        mDithering = val;
        mDirty = true;
    }
}

void Material::setAlphaTest(bool val)
{
    if(val != mAlphaTest)
    {
        mAlphaTest = val;
        mDirty = true;
    }
}

void Material::setPremultipliedAlpha(bool val)
{
    if(val != mPremultipliedAlpha)
    {
        mPremultipliedAlpha = val;
        mDirty = true;
    }
}

// void Material::setVisible(bool val)
// {
//     if(val != mVisible)
//     {
//         mVisible = val;
//         mDirty = true;
//     }
// }

// void Material::setToneMapped(bool val)
// {
//     if(val != mToneMapped)
//     {
//         mToneMapped = val;
//         mDirty = true;
//     }
// }
void Material::setUniformByName(const std::string &name,IUniform *uniform)
{
    POCELAIN_ASSERT(name.size()&&uniform);
    auto it = mMapNameUniform.find(name);
    if(it != mMapNameUniform.end())
    {
        mMapNameUniform[name].reset(uniform);
    }
    else
    {
        mMapNameUniform.insert(std::make_pair
                               (name,RefPtr<IUniform>(uniform)));
    }
}
RefPtr<IUniform> Material::getUniformByName(const std::string &name)
{
    POCELAIN_ASSERT(name.size());
    auto it = mMapNameUniform.find(name);
    if(it!=mMapNameUniform.end())
    {
        return it->second;
    }
    return RefPtr<IUniform>();
}
POCELAIN_NAMESPACE_END
